<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class membership extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model(array('admin_commoncall','admin_settings_model','admin_membership_model'));

		$this->admin_commoncall->check_admin_login();
		$this->template->set_theme('admin');
		$this->template->set_layout('default');
		//$this->template->set_partial('side_menu','layouts/side_menu');
		//$this->template->set_partial('nav_bar','layouts/nav_bar');

	}
	
	function index($id=NULL)
	{
		
		$id = $_GET['code'];
		$data['id'] = $id;
		$data['membership'] = $this->admin_membership_model->showlist();
		$data['member'] = $this->admin_membership_model->get_memtypeinfo_byid($id);
		//var_dump($data['member']);
		//die();
		
		$this->template->title('Welcome', 'Ypage.com')
		->set_partial('nav_bar','layouts/nav_bar')
		->set_partial('side_menu','layouts/side_menu')
		->set_partial('footer','footer/footer')
		->build('membership/membership',$data);
	}
	
	
	function insert() {
		$id = $_POST['mem_id'];
		if ($this->input->post('membership')) {
			$this->form_validation->set_rules('rdo_contact', 'rdo_contact', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_address', 'rdo_address', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_contact_person', 'rdo_contact_person', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_email', 'rdo_email', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_website', 'rdo_website', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_logo', 'rdo_logo', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_banner', 'rdo_banner', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_photo', 'rdo_photo', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_video', 'rdo_video', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_product','rdo_product','required|xss_clean');
			$this->form_validation->set_rules('rdo_deal','rdo_deal','required|xss_clean');
			//$this->form_validation->set_rules('rdo_brochure', 'rdo_brochure', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_google_map', 'rdo_google_map', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_email_alert', 'rdo_email_alert', 'required|xss_clean');
			//$this->form_validation->set_rules('rdo_sms', 'rdo_sms', 'required|xss_clean');
			$this->form_validation->set_rules('keyword_limit', 'keyword_limit', 'required|xss_clean');
			$this->form_validation->set_rules('photo_limit','photo_limit','required|xss_clean');
			$this->form_validation->set_rules('video_limit','video_limit','required|xss_clean');
			$this->form_validation->set_rules('price', 'price', 'required|xss_clean');
			$this->form_validation->set_rules('rdo_satisfaction_tag', 'rdo_satisfaction_tag', 'required|xss_clean');
			
			
			$rdo_contact = $this->input->post('rdo_contact');
			$rdo_address = $this->input->post('rdo_address');
			$rdo_contact_person = $this->input->post('rdo_contact_person');
			$rdo_email = $this->input->post('rdo_email');
			$rdo_website = $this->input->post('rdo_website');
			$rdo_logo = $this->input->post('rdo_logo');
			$rdo_banner = $this->input->post('rdo_banner');
			$rdo_photo = $this->input->post('rdo_photo');
			$rdo_video = $this->input->post('rdo_video');
			$rdo_product = $this->input->post('rdo_product');
			$rdo_deal = $this->input->post('rdo_deal');
			// $rdo_brochure = $this->input->post('rdo_brochure');
			$rdo_google_map = $this->input->post('rdo_google_map');
			$rdo_email_alert = $this->input->post('rdo_email_alert');
			//$rdo_sms = $this->input->post('rdo_sms');
			$keyword_limit = $this->input->post('keyword_limit');
			$photo_limit=$this->input->post('photo_limit');
			$video_limit=$this->input->post('video_limit');
			$price = $this->input->post('price');
			$rdo_satisfaction_tag = $this->input->post('rdo_satisfaction_tag');
			$mem_data = array('contact_no' => $rdo_contact,
					'address' => $rdo_address,
					'contact_person' => $rdo_contact_person,
					'email' => $rdo_email,
					'website' => $rdo_website,
					'logo' => $rdo_logo,
					'banner' => $rdo_banner,
					'video' => $rdo_video,
					'brochure' => 0,
					'photo' => $rdo_photo,
					'google_map' => $rdo_google_map,
					'email_alert' => $rdo_email_alert,
					//'mobile_alert' => $rdo_sms,
					'keyword_limit' => $keyword_limit,
					'photo_limit'=>$photo_limit,
					'video_limit'=>$video_limit,
					'price' => $price,
					'satisfaction_tag' => $rdo_satisfaction_tag,
					'products' => $rdo_product,
					'deal' => $rdo_deal,
			);
			
			
			if ($this->form_validation->run()) {
				$this->db->where('code', $id);
				if ($this->config->item('mode') != 'DEMO')
					$this->db->update('membership', $mem_data);
				redirect('secure/membership?code=' . $id);
			}
			else {
				$this->session->set_flashdata('message', 'All Fields are mendatory');
				redirect('secure/membership?code=' . $id);
			}
		}
		// redirect('secure/keyword/index?cat_id='.$cat_id);
	}
}